<script setup>
import { ref, onMounted } from 'vue'
import { airspaceUsageServer } from '@/api'
import * as charts from 'echarts'
const optionData = {
  tooltip: {
    trigger: 'axis',
    borderColor: '#0F2638',
    backgroundColor: '#0F2638DB',
    textStyle: {
      color: '#fff',
      fontSize: 14
    },
    formatter: function (params) {
      return `<div>${params[0].name}<br/> ${params[0].value} 个</div>`
    }
  },
  backgroundColor: 'transparent',
  grid: {
    left: '12%',
    top: '8%',
    bottom: '12%',
    right: '0%'
  },
  xAxis: {
    data: [],
    axisTick: {
      show: false
    },
    axisLine: {
      lineStyle: {
        color: 'rgba(255, 129, 109, 0.1)',
        width: 1 //这里是为了突出显示加上的
      }
    },
    axisLabel: {
      interval: 0,
      rotate: 20,
      textStyle: {
        color: '#999',
        fontSize: 12
      }
    }
  },
  yAxis: [
    {
      splitNumber: 0,
      axisTick: {
        show: false
      },
      axisLine: {
        lineStyle: {
          color: 'rgba(255, 129, 109, 0.1)',
          width: 1 //这里是为了突出显示加上的
        }
      },
      axisLabel: {
        textStyle: {
          color: '#999'
        }
      },
      splitArea: {
        areaStyle: {
          color: 'rgba(255,255,255,.5)'
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: 'rgba(255, 129, 109, 0.1)',
          width: 0.5,
          type: 'dashed'
        }
      }
    }
  ],
  series: [
    {
      type: 'pictorialBar',
      barCategoryGap: '0%',
      symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
      label: {
        show: true,
        position: 'top',
        // distance: 15,
        color: '#fff',
        // fontWeight: "bolder",
        fontSize: 12
      },
      data: [
        {
          value: '',
          itemStyle: {
            color: new charts.graphic.LinearGradient(
              0,
              0,
              0,
              1, // 渐变方向，从上到下
              [
                { offset: 0, color: '#41FFA7' }, // 柱图上端颜色
                { offset: 1, color: 'transparent' } // 柱图下端颜色
              ]
            ),
            borderColor: '#41FFA7',
            borderWidth: 1
          }
        },
        {
          value: '',
          itemStyle: {
            color: new charts.graphic.LinearGradient(
              0,
              0,
              0,
              1, // 渐变方向，从上到下
              [
                { offset: 0, color: '#41FFE1' }, // 柱图上端颜色
                { offset: 1, color: 'transparent' } // 柱图下端颜色
              ]
            ),
            borderColor: '#41FFE1',
            borderWidth: 1
          }
        },
        {
          value: '',
          itemStyle: {
            color: new charts.graphic.LinearGradient(
              0,
              0,
              0,
              1, // 渐变方向，从上到下
              [
                { offset: 0, color: '#22A7FF' }, // 柱图上端颜色
                { offset: 1, color: 'transparent' } // 柱图下端颜色
              ]
            ),
            borderColor: '#22A7FF',
            borderWidth: 1
          }
        },
        {
          value: '',
          itemStyle: {
            color: new charts.graphic.LinearGradient(
              0,
              0,
              0,
              1, // 渐变方向，从上到下
              [
                { offset: 0, color: '#CFFF41' }, // 柱图上端颜色
                { offset: 1, color: 'transparent' } // 柱图下端颜色
              ]
            ),
            borderColor: '#CFFF41',
            borderWidth: 1
          }
        },
        {
          value: '',
          itemStyle: {
            color: new charts.graphic.LinearGradient(
              0,
              0,
              0,
              1, // 渐变方向，从上到下
              [
                { offset: 0, color: '#FF9B41' }, // 柱图上端颜色
                { offset: 1, color: 'transparent' } // 柱图下端颜色
              ]
            ),
            borderColor: '#FF9B41',
            borderWidth: 1
          }
        },
        {
          value: '',
          itemStyle: {
            color: new charts.graphic.LinearGradient(
              0,
              0,
              0,
              1, // 渐变方向，从上到下
              [
                { offset: 0, color: '#cca700' }, // 柱图上端颜色
                { offset: 1, color: 'transparent' } // 柱图下端颜色
              ]
            ),
            borderColor: '#FF9B41',
            borderWidth: 1
          }
        },
        {
          value: '',
          itemStyle: {
            color: new charts.graphic.LinearGradient(
              0,
              0,
              0,
              1, // 渐变方向，从上到下
              [
                { offset: 0, color: '#76521b' }, // 柱图上端颜色
                { offset: 1, color: 'transparent' } // 柱图下端颜色
              ]
            ),
            borderColor: '#FF9B41',
            borderWidth: 1
          }
        },
        {
          value: '',
          itemStyle: {
            color: new charts.graphic.LinearGradient(
              0,
              0,
              0,
              1, // 渐变方向，从上到下
              [
                { offset: 0, color: '#6a9955' }, // 柱图上端颜色
                { offset: 1, color: 'transparent' } // 柱图下端颜色
              ]
            ),
            borderColor: '#FF9B41',
            borderWidth: 1
          }
        }
      ],
      z: 10
    }
  ]
}
const option = ref(optionData)
const companys = ref(0)
const getAirspaceUsage = async () => {
  const res = await airspaceUsageServer()
  const { companyCount, companyList } = res.data
  companys.value = companyCount
  option.value.xAxis.data = []
  companyList.forEach((item, index) => {
    option.value.xAxis.data.push(item.companyName)
    if (option.value.series[0]?.data[index]?.value)
      option.value.series[0].data[index].value = item.count
  })
}
onMounted(() => {
  getAirspaceUsage()
})
</script>
<template>
  <div class="card">
    <CommonTitle title="空域使用情况" />
    <div class="top">
      <div class="enterprise-num">
        <span>企业总数</span>
        <i>/个</i>
      </div>
      <div class="num">
        <span><NumberAnimate :count="companys"></NumberAnimate></span>
      </div>
    </div>
    <div class="unit">个</div>
    <div class="chart">
      <Charts :option="option" container="4" />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.card {
  padding: 10px;
  .top {
    background: url('@img/management/fly-situation-bg.png');
    background-size: 100% 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
    .enterprise-num {
      flex: 1;
      display: flex;
      flex-direction: column;
      margin-left: 26px;
      i {
        color: #2f9cff;
        font-size: 14px;
        margin-left: 3px;
        vertical-align: middle;
        font-style: normal;
      }
    }
    .num {
      flex: 1;
      text-align: center;

      &:deep(.odometer-numbers) {
        span {
          font-family: DINAlternate;
          font-size: 28px;
          line-height: 28px;
          color: #ffffff;
          letter-spacing: 5px;
          text-align: center;
          background: linear-gradient(to bottom, #ffffff 0%, #00d5ff 100%);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
        }
      }
    }
  }
  .unit {
    width: 12px;
    height: 46px;
    font-weight: 500;
    font-size: 14px;
    margin-left: 3px;
    vertical-align: middle;
    font-style: normal;
  }
}

.chart {
  width: 100%;
  height: 330px;
}
</style>
